﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace MainProGrid
{
    public class CustomPropertyDescriptor : PropertyDescriptor  
    {
        CustomProperty MyPro;
        public CustomPropertyDescriptor(ref CustomProperty myProperty, Attribute[] attrs): base(myProperty.Name, attrs)
        {
            MyPro = myProperty;
        }

        #region PropertyDescriptor 重写方法
        public override bool CanResetValue(object component)
        {
            return false;
        }
        public override Type ComponentType
        {
            get
            {
                return null;
            }
        }
        public override object GetValue(object component)
        {
            return MyPro.Value;
        }
        public override string Description
        {
            get
            {
                return MyPro.Description;
            }
        }
        public override string Category
        {
            get
            {
                return MyPro.GroupName;
            }
        }
        public override string DisplayName
        {
            get
            {
                return MyPro.ChinaName != "" ? MyPro.ChinaName : MyPro.Name;
            }
        }
        public override bool IsReadOnly
        {
            get
            {
                return MyPro.ReadyOnly;
            }
        }
        public override void ResetValue(object component)
        {
            //Have to implement  
        }
        public override bool ShouldSerializeValue(object component)
        {
            return false;
        }
        public override void SetValue(object component, object value)
        {
            MyPro.Value = value;
        }
        public override TypeConverter Converter
        {
            get
            {
                return MyPro.Converter;
            }
        }
        public override Type PropertyType
        {
            get
            {
                return MyPro.PropertyType;
            }
        }
        public override object GetEditor(Type editorBaseType)
        {
            return MyPro.Editor == null ? base.GetEditor(editorBaseType) : MyPro.Editor;
        }
        #endregion  

    }
}
